package com.ysg.binding.viewadapter;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;

import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.ysg.binding.command.BindingCommand;
import com.ysg.widget.refresh.YRefreshView;

public class RefreshViewAdapter {

    @BindingAdapter(value = {"onRefreshCommand", "onLoadMoreCommand"}, requireAll = false)
    public static void setListener(YRefreshView refreshView, BindingCommand onRefreshCommand, BindingCommand onLoadMoreCommand) {
        refreshView.getRefreshLayout().setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                if (onRefreshCommand != null){
                    onRefreshCommand.execute();
                }
            }
        }) ;
        refreshView.getRefreshLayout().setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                if (onLoadMoreCommand != null){
                    onLoadMoreCommand.execute();
                }
            }
        }) ;
    }






}
